using System;



namespace FineCollection.Simplex
{
    /// <summary>
    /// A couple of different types members.
    /// </summary>
    /// <typeparam name="TA">first member type.</typeparam>
    /// <typeparam name="TB">second member type.</typeparam>
    /// <seealso cref="Pair{T}"/>
    public struct Couple<TA,TB> : IEquatable<Couple<TA, TB>>
    {
        /// <summary>
        /// The first member of the pair.
        /// </summary>
        public readonly TA A;

        /// <summary>
        /// The second member of the pair.
        /// </summary>
        public readonly TB B;


        /// <summary>
        /// Trivial constructor.
        /// </summary>
        /// <param name="a">the first member.</param>
        /// <param name="b">the second member.</param>
        public Couple(TA a, TB b)
        {
            A = a;
            B = b;
        }


        public bool Equals(Couple<TA, TB> that)
        {
            return Equals(this.A, that.A) && Equals(this.B, that.B);
        }


        public override bool Equals(object that)
        {
            if (ReferenceEquals(null, that)) return false;
            if (that.GetType() != typeof (Couple<TA, TB>)) return false;
            return Equals((Couple<TA, TB>) that);
        }


        public override int GetHashCode()
        {
            // ReSharper disable CompareNonConstrainedGenericWithNull
            return (A == null ? 0 : A.GetHashCode())
                 ^ (B == null ? 0 : B.GetHashCode());
            // ReSharper restore CompareNonConstrainedGenericWithNull
        }


        public static bool operator == (Couple<TA, TB> left, Couple<TA, TB> right)
        {
            return left.Equals(right);
        }


        public static bool operator != (Couple<TA, TB> left, Couple<TA, TB> right)
        {
            return !left.Equals(right);
        }


        public override string ToString()
        {
            return '(' + A.ToString() + ',' + B.ToString() + ')';
        }
    }
}